package com.tuling.learnmongodb.controller;

import com.mongodb.client.result.DeleteResult;
import com.tuling.learnmongodb.common.ResponseModel;
import com.tuling.learnmongodb.model.Logistic;
import com.tuling.learnmongodb.model.Order;
import com.tuling.learnmongodb.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/addOrder")
    public ResponseModel<Object> addOrder(@RequestBody Order order){
        orderService.addOrder(order);
        return new ResponseModel<Object>();
    }

    @PostMapping("/updateOrderAndLogistaics")
    public ResponseModel<Object> updateOrderAndLogistaics(@RequestBody Logistic logistic){
        orderService.updateOrderAndLogistaics(logistic);
        return new ResponseModel<Object>();
    }
    @GetMapping("/selectOrderById/{id}")
    public ResponseModel<Order> selectOrderById(@PathVariable String id){
        Order order = orderService.selectOrderById(id);
        ResponseModel<Order> result = new ResponseModel<Order>();
        result.setData(order);
        return result;
    }
    @GetMapping("selectOrderList")
    public ResponseModel<List<Order>> selectOrderList() {
        ResponseModel<List<Order>> result = new ResponseModel<List<Order>>();
        result.setData(orderService.selectOrderList());
        return result;
    }

    @GetMapping("/deleteOrderById/{id}")
    public ResponseModel<Boolean> deleteOrderById(@PathVariable String id) {
        ResponseModel<Boolean> result = new ResponseModel<Boolean>();
        result.setData(orderService.deleteOrderById(id));
        return result;
    }
}
